package com.hbue.water.controller;

import com.github.pagehelper.PageInfo;
import com.hbue.water.common.CommonResult;
import com.hbue.water.common.ResponseCode;
import com.hbue.water.entity.Salary;
import com.hbue.water.service.SalaryService;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yushu
 * @date 2021/12/27
 * @apiNate
 */
@RestController
@RequestMapping("/salary")
@Slf4j
@ApiModel("计算工资Controller")
public class SalaryController {

    @Autowired
    private SalaryService salaryService;

    @ApiOperation("分页查询所有送水工工资")
    @GetMapping("/listSalaryPage/{pageNum}/{pageSize}")
    public CommonResult<PageInfo> listSalary(
            @ApiParam(name="pageNum",value="当前页",required = true)
            @PathVariable("pageNum") Integer pageNum,
            @ApiParam(name = "pageSize", value = "每页数据量", required = true)
            @PathVariable("pageSize") Integer pageSize){
        PageInfo<Salary> salaryPageInfo = salaryService.listSalary(pageNum, pageSize);
        return new CommonResult<>(ResponseCode.RESPONSE_SUCCESS, "ok", salaryPageInfo);
    }

    @ApiOperation("显示所有送水工的工资")
    @GetMapping("/calcSalary")
    public CommonResult<List<Salary>> calcWorkerSalary(){
        List<Salary> salaryList = salaryService.calcSalary();
        log.info("worker salary list size = "+salaryList.size());
        return new CommonResult<>(ResponseCode.RESPONSE_SUCCESS, "ok", salaryList);
    }

    @ApiOperation("根据时间区间查询送水工工资信息")
    @GetMapping("/searchCalcSalary")
    public CommonResult<List<Salary>> searchCalcWorkerSalary(
            @ApiParam(name = "beginDate", value = "搜索条件", required = true)
            @RequestParam String beginDate,
            @ApiParam(name = "endDate", value = "搜索条件")
            @RequestParam String endDate){
        List<Salary> salaryList = salaryService.searchSalaryByCondition(beginDate, endDate);
        return new CommonResult<>(ResponseCode.RESPONSE_SUCCESS, "ok", salaryList);
    }
}
